<?php

namespace app\api\validate;

use think\Validate;

class UserAddressValidate extends Validate
{
    protected $rule = [
        'receiver_name' => 'require',
        'receiver_phone' => 'require|mobile',
        'province' => 'require|max:30',
        'city' => 'require|max:30',
        'county' => 'require|max:30',
        'address' => 'require|max:100',
        'is_default' => 'in:0,1',
    ];

    protected $message = [
        'receiver_name.require' => '收货人不能为空!',
        'receiver_phone.require' => '收货人手机号不能为空!',
        'receiver_phone.mobile' => '请输入正确的收货人手机号!',
        'province.require' => '所在省份不能为空!',
        'city.require' => '所在城市不能为空!',
        'county.require' => '所在县或市区不能为空!',
        'address.require' => '详细地址不能为空!',
        'is_default.in' => '非法请求!',
    ];

    public function sceneEdit()
    {
        return $this->only(['address_id','receiver_name','receiver_phone','province','city','county','address','is_default'])
                    ->append('address_id','require|integer');
    }
}